package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"studygin-2/model"
)

func CurrentUser(c *gin.Context) {
	userId, err := model.ExtractTokenID(c)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"error": err.Error(),
		})
	}
	user, err := model.GetUserByID(userId)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"error": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"data":    user,
		"message": "success",
	})
}
